package com.pro.core.system;

import com.pro.core.util.SystemInfoPrinter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 系统启动服务，用于检查系统状态及打印系统信息
 */
@Component
class SystemInistService {
    private SystemInistService systemInistService;

    @Autowired
    private Environment environment;

    @PostConstruct
    private void inist() {
        systemInistService = this;
        initConfigs();
        SystemInfoPrinter.printInfo("系统初始化信息", getSystemInfo());
    }


    private final static Map<String, String> DEFAULT_CONFIGS = new HashMap<>();

    private void initConfigs() {
        // 1. 读取数据库全部配置信息

    }

    private Map<String, String> getSystemInfo() {

        Map<String, String> infos = new LinkedHashMap<>();

        infos.put(SystemInfoPrinter.CREATE_PART_COPPER + 0, "系统信息");
        // 测试获取application-db.yml配置信息
        infos.put("系统名称", environment.getProperty("pro.name"));
        infos.put("服务器端口", environment.getProperty("server.port"));
        infos.put("数据库用户", environment.getProperty("spring.datasource.druid.username"));
        infos.put("数据库地址", environment.getProperty("spring.datasource.druid.url"));
        infos.put("调试级别", environment.getProperty("logging.level.com.pro"));

        // 测试获取application-core.yml配置信息
        infos.put(SystemInfoPrinter.CREATE_PART_COPPER + 1, "模块状态");
        infos.put("邮件", environment.getProperty("pro.notify.mail.enable"));
        infos.put("短信", environment.getProperty("pro.notify.sms.enable"));
        infos.put("模版消息", environment.getProperty("pro.notify.wx.enable"));
        infos.put("快递信息", environment.getProperty("pro.express.enable"));
        infos.put("快递鸟ID", environment.getProperty("pro.express.appId"));
        infos.put("对象存储", environment.getProperty("pro.storage.active"));
        infos.put("本地对象存储路径", environment.getProperty("pro.storage.local.storagePath"));
        infos.put("本地对象访问地址", environment.getProperty("pro.storage.local.address"));
        infos.put("本地对象访问端口", environment.getProperty("pro.storage.local.port"));

        // 微信相关信息
        infos.put(SystemInfoPrinter.CREATE_PART_COPPER + 2, "微信相关");
        infos.put("微信APP KEY", environment.getProperty("pro.wx.app-id"));
        infos.put("微信APP-SECRET", environment.getProperty("pro.wx.app-secret"));
        infos.put("微信支付MCH-ID", environment.getProperty("pro.wx.mch-id"));
        infos.put("微信支付MCH-KEY", environment.getProperty("pro.wx.mch-key"));
        infos.put("微信支付通知地址", environment.getProperty("pro.wx.notify-url"));
        infos.put("微信支付机构ORG-ID", environment.getProperty("pro.wx.org-id"));

        //测试获取System表配置信息
        //获取数据库部分信息展示

        return infos;
    }
}
